package com.dhnsoft.代码随想录.栈与队列;

import java.util.ArrayDeque;
import java.util.LinkedList;
import java.util.Queue;

/**
 * ClassName: d02_225_用队列实现栈
 * Package: com.dhnsoft.代码随想录.栈与队列
 * Description:
 *
 * @Author dhn
 * @Create 2024/3/25 13:06
 * @Version 1.0
 */
public class d02_225_用队列实现栈 {


}

class MyStack {

    Queue<Integer> queueIn;
    Queue<Integer> queueOut;

    public MyStack() {
        queueIn = new LinkedList<>();
        queueOut = new LinkedList<>();
    }

    public void push(int x) {
        queueIn.offer(x);
        while (!queueOut.isEmpty()){
            queueIn.offer(queueOut.poll());
        }
        Queue<Integer> tempQueue;
        tempQueue = queueIn;
        queueIn = queueOut;
        queueOut = tempQueue;
    }

    public int pop() {
        return queueOut.poll();
    }

    public int top() {
        return queueOut.peek();
    }

    public boolean empty() {
        return queueIn.isEmpty()&&queueOut.isEmpty();
    }

}
